//
//  MainWebViewController.m
//  BJYShoppingMall
//
//  Created by Coder on 16/1/18.
//  Copyright © 2016年 BJY12. All rights reserved.
//

#import "MainWebViewController.h"
#import "UIBarButtonItem+CommomBarButtonItem.h"
#import "AppDelegate.h"

@interface MainWebViewController ()

@end

@implementation MainWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    
    [baseWebView.scrollView setContentInset:UIEdgeInsetsMake(0,0,0,0)];
    
    [self setNaviBar];
    
    
    if (_isSharekView) {
        [self setShareRightItem];
    }
    
    
}

-(void)setNaviBar
{
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem createBackBBTframe:CGRectMake(0, 0, 50, self.navigationController.navigationBar.bounds.size.height) isShowArrow:YES isShowTitle:NO target:self action:@selector(back:)];
    
    
    //标题栏字体大小
    NSDictionary *attributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],UITextAttributeTextColor,[UIFont systemFontOfSize:18],UITextAttributeFont, nil];
    [self.navigationController.navigationBar setTitleTextAttributes:attributes];
    

    
}
- (void)back:(UIViewController*)viewController
{
    // 最低控制器无需返回
    
    [self.navigationController popViewControllerAnimated:YES];
}




-(void)setShareRightItem{
    
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem createRightImgBBTframe:CGRectMake(0, 0, 80, self.navigationController.navigationBar.bounds.size.height) imgName:@"icon_share" isShowArrow:YES isShowTitle:NO target:self action:@selector(addBankCardAction:)];
}
-(void)hideNaviBar{
    
    self.navigationItem.rightBarButtonItem =nil;
}

-(void)addBankCardAction:(id)sender
{
    NSString *shareText = self.navigationItem.title;//分享内嵌文字
    UIImage *shareImage = [UIImage imageNamed:@"bjylogo"];//分享内嵌图片
    //分享包括
    NSMutableArray *sharedList=[[NSMutableArray alloc]init];
    

}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    [super webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
    NSURL *currentUrl=request.URL;
    NSString *urlStr=currentUrl.absoluteString;//原始链接，微信支付不能使用全小写参数
    NSString *stringUrl = [urlStr lowercaseString];//转成小写的链接，用于判断业务
    
    //如果是产品详情页，那就显示分享按钮，不是则隐藏
    if ([stringUrl rangeOfString:@"activities/detail"].location != NSNotFound) {
        
        [self setNaviBar];
        
    }else{
        [self hideNaviBar];
    }
    
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
